package com.gitee.huanminabc.fastboot.event;

import java.time.Clock;
import java.util.EventObject;


public abstract class AppEvent extends EventObject {

	/** use serialVersionUID from Spring 1.2 for interoperability. */
	private static final long serialVersionUID = 7099057708183571937L;

	/** System time when the event happened. */
	private final long timestamp;

	//子类可以重写这个方法,用于异步的时候给线程名称用
	public String getEventName(){
		return this.getClass().getSimpleName();
	}


	/**
	 * Create a new {@code AppEvent} with its {@link #getTimestamp() timestamp}
	 * set to {@link System#currentTimeMillis()}.
	 * @param source the object on which the event initially occurred or with
	 * which the event is associated (never {@code null})
	 * @see #AppEvent(Object, Clock)
	 */
	public AppEvent(Object source) {
		super(source);
		this.timestamp = System.currentTimeMillis();
	}

	/**
	 * Create a new {@code AppEvent} with its {@link #getTimestamp() timestamp}
	 * set to the value returned by {@link Clock#millis()} in the provided {@link Clock}.
	 * <p>This constructor is typically used in testing scenarios.
	 * @param source the object on which the event initially occurred or with
	 * which the event is associated (never {@code null})
	 * @param clock a clock which will provide the timestamp
	 * @since 5.3.8
	 * @see #AppEvent(Object)
	 */
	public AppEvent(Object source, Clock clock) {
		super(source);
		this.timestamp = clock.millis();
	}


	/**
	 * Return the time in milliseconds when the event occurred.
	 * @see #AppEvent(Object)
	 * @see #AppEvent(Object, Clock)
	 */
	public final long getTimestamp() {
		return this.timestamp;
	}

}